

import re  # 添加这行导入语句
import json  # 同时需要导入json模块

# aieduKnowledgeList: "Python标准库使用,字符串"
# 解析```json ```之间的内容,并获取 aieduKnowledgeList 字段，从 aieduKnowledgeList 过滤


def main(arg1: str, arg2: str) -> dict:
    pattern = r'```json\n([\s\S]*?)\n```(?![\s\S]*```)'
    match = re.search(pattern, arg1)
    json_str = match.group(1)
    json_obj = json.loads(json_str)
    ai_result_aieduKnowledgeList = json_obj["aieduKnowledgeList"]
    aieduKnowledgeList = arg2.split(',')

    # 过滤出包含aieduKnowledgeList中任意一项的内容
    filtered_items = [
        item for item in ai_result_aieduKnowledgeList
        if any(knowledge in item["content"] for knowledge in aieduKnowledgeList)
    ]

    # 构建返回的JSON结构
    # result_json = {
    #     "content": json_obj["content"],
    #     "analysis": json_obj["analysis"],
    #     "rightKey": json_obj["rightKey"],
    #     "aieduAnswerList": json_obj["aieduAnswerList"],
    #     "filtered_aieduKnowledgeList": filtered_items
    # }

    return {
        "result": filtered_items
    }


# 使用示例
json_data = """```json
{
  "content": "在 Python 的标准库中，哪些方法可以用于处理字符串？",
  "analysis": "此题考查 Python 标准库中用于处理字符串的方法。\\n- `str.split()` 方法可以将字符串按照指定的分隔符进行分割。\\n- `str.join()` 方法可以将多个字符串连接起来。\\n- `str.replace()` 方法可以替换字符串中的子串。\\n- `len()` 函数可以计算字符串的长度。\\n其中，`str.split()` 和 `str.replace()` 是处理字符串的重要方法。",
  "rightKey": "A,C",
  "aieduAnswerList": [
    {
      "answer": "str.split()",
      "answerSort": "A"
    },
    {
      "answer": "int()",
      "answerSort": "B"
    },
    {
      "answer": "str.replace()",
      "answerSort": "C"
    },
    {
      "answer": "len()",
      "answerSort": "D"
    }
  ],
  "aieduKnowledgeList": [
    {
      "content": "字符串处理",
      "weight": 0.5
    },
    {
      "content": "标准库函数",
      "weight": 0.3
    },
    {
      "content": "split方法",
      "weight": 0.2
    }
  ]
}
```"""

result = main(json_data, "字符串处理,标准库函数")
print(result["result"])
